/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainMenuForm.java
 *
 * Created on 10 Nov 11, 15:53:10
 */
package MenuUtamaSistem;

/**
 *
 * @author asus
 */
import Pembelian.FormPembelian;
import Penjualan.FormPenjualan;
import MembuatLaporan.LaporanMingguan;
import BuktiTransaksi.BuktiTransaksiForm;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class MainMenuForm extends javax.swing.JFrame {

    /** Creates new form MainMenuForm */
    public MainMenuForm() {
        initComponents();
        LoginDialog.show();
        LoginDialog.setLocation(600, 250);
        menuBarForm.setVisible(false);
//        detailPanel.setVisible(false);
        Login.setMain(this);



    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LoginDialog = new javax.swing.JDialog();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        userText = new javax.swing.JTextField();
        passText = new javax.swing.JPasswordField();
        loginButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        bgLabel = new javax.swing.JLabel();
        panelUserDetail = new javax.swing.JPanel();
        userField = new javax.swing.JLabel();
        jabatanText = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        copyrightLabel = new javax.swing.JLabel();
        logo = new javax.swing.JLabel();
        judulLabel = new javax.swing.JLabel();
        menuBarForm = new javax.swing.JMenuBar();
        menuMenu = new javax.swing.JMenu();
        penjualanmenuItem = new javax.swing.JMenuItem();
        pembelianmenuItem = new javax.swing.JMenuItem();
        laporanMenuItem = new javax.swing.JMenuItem();
        buktiTransMenuItem = new javax.swing.JMenuItem();
        logoutMenuItem = new javax.swing.JMenuItem();
        exitmenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        helpMenuItem = new javax.swing.JMenuItem();

        LoginDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        LoginDialog.setTitle("Login Form");
        LoginDialog.setBackground(new java.awt.Color(204, 204, 204));
        LoginDialog.setIconImage(null);
        LoginDialog.setMinimumSize(new java.awt.Dimension(400, 330));
        LoginDialog.setResizable(false);
        LoginDialog.getContentPane().setLayout(null);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel2.setText("Login Form");
        jPanel3.add(jLabel2);
        jLabel2.setBounds(10, 20, 140, 30);

        jLabel3.setText("User ID");
        jPanel3.add(jLabel3);
        jLabel3.setBounds(40, 110, 60, 20);

        jLabel4.setText("Password");
        jPanel3.add(jLabel4);
        jLabel4.setBounds(40, 160, 60, 20);

        userText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userTextActionPerformed(evt);
            }
        });
        jPanel3.add(userText);
        userText.setBounds(120, 110, 130, 20);

        passText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                passTextActionPerformed(evt);
            }
        });
        jPanel3.add(passText);
        passText.setBounds(120, 160, 130, 20);

        loginButton.setText("Login");
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });
        jPanel3.add(loginButton);
        loginButton.setBounds(260, 220, 110, 23);

        exitButton.setText("Exit");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });
        jPanel3.add(exitButton);
        exitButton.setBounds(80, 220, 130, 23);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MenuUtamaSistem/login_icon.gif"))); // NOI18N
        jPanel3.add(jLabel5);
        jLabel5.setBounds(130, 0, 270, 300);

        LoginDialog.getContentPane().add(jPanel3);
        jPanel3.setBounds(0, 0, 400, 300);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SP3EF by MAFY");
        getContentPane().setLayout(null);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(null);

        bgLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MenuUtamaSistem/pulsa-elektrik - Copy2.jpg"))); // NOI18N
        bgLabel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255, 0, 0), 3, true));
        jPanel1.add(bgLabel);
        bgLabel.setBounds(0, 120, 620, 230);

        panelUserDetail.setBackground(new java.awt.Color(255, 255, 255));
        panelUserDetail.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(153, 153, 153), new java.awt.Color(0, 0, 0)));
        panelUserDetail.setLayout(null);

        userField.setBackground(new java.awt.Color(255, 255, 255));
        userField.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        userField.setForeground(new java.awt.Color(255, 0, 0));
        panelUserDetail.add(userField);
        userField.setBounds(80, 20, 100, 30);

        jabatanText.setBackground(new java.awt.Color(255, 255, 255));
        jabatanText.setFont(new java.awt.Font("Trebuchet MS", 0, 18));
        jabatanText.setForeground(new java.awt.Color(255, 0, 0));
        panelUserDetail.add(jabatanText);
        jabatanText.setBounds(260, 20, 130, 30);

        jLabel1.setText("User ID");
        panelUserDetail.add(jLabel1);
        jLabel1.setBounds(10, 30, 60, 14);

        jLabel6.setText("Jabatan");
        panelUserDetail.add(jLabel6);
        jLabel6.setBounds(200, 30, 80, 14);

        jPanel1.add(panelUserDetail);
        panelUserDetail.setBounds(30, 50, 400, 60);

        copyrightLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        copyrightLabel.setForeground(new java.awt.Color(255, 0, 0));
        copyrightLabel.setText("Copyright © 2011 MAFY - All Rights Reserved");
        jPanel1.add(copyrightLabel);
        copyrightLabel.setBounds(360, 370, 260, 20);

        logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/MenuUtamaSistem/logoMAFY.png"))); // NOI18N
        jPanel1.add(logo);
        logo.setBounds(460, 10, 160, 110);

        judulLabel.setFont(new java.awt.Font("Tempus Sans ITC", 1, 18));
        judulLabel.setText("Sistem Pencatatan Penjualan Pulsa");
        jPanel1.add(judulLabel);
        judulLabel.setBounds(10, 0, 440, 40);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 619, 400);

        menuMenu.setText("Menu");

        penjualanmenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.CTRL_MASK));
        penjualanmenuItem.setText("Penjualan");
        penjualanmenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                penjualanmenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(penjualanmenuItem);

        pembelianmenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        pembelianmenuItem.setText("Pembelian");
        pembelianmenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pembelianmenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(pembelianmenuItem);

        laporanMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.CTRL_MASK));
        laporanMenuItem.setText("Laporan Keuangan ");
        laporanMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                laporanMenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(laporanMenuItem);

        buktiTransMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
        buktiTransMenuItem.setText("Bukti Transaksi");
        buktiTransMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buktiTransMenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(buktiTransMenuItem);

        logoutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        logoutMenuItem.setText("Logout");
        logoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutMenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(logoutMenuItem);

        exitmenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, java.awt.event.InputEvent.CTRL_MASK));
        exitmenuItem.setText("Exit");
        exitmenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitmenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(exitmenuItem);

        menuBarForm.add(menuMenu);

        helpMenu.setText("Help");

        helpMenuItem.setText("Help");
        helpMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(helpMenuItem);

        menuBarForm.add(helpMenu);

        setJMenuBar(menuBarForm);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-636)/2, (screenSize.height-462)/2, 636, 462);
    }// </editor-fold>//GEN-END:initComponents

    private void penjualanmenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_penjualanmenuItemActionPerformed
        // TODO add your handling code here:
        FormPenjualan call = new FormPenjualan();
        call.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_penjualanmenuItemActionPerformed

    private void pembelianmenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pembelianmenuItemActionPerformed
        // TODO add your handling code here:
        FormPembelian call;
        try {
            call = new FormPembelian();
            call.setVisible(true);
            this.setVisible(false);
        } catch (Exception ex) {
            Logger.getLogger(MainMenuForm.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_pembelianmenuItemActionPerformed

    private void laporanMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_laporanMenuItemActionPerformed
        // TODO add your handling code here:
        LaporanMingguan call = new LaporanMingguan();
        call.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_laporanMenuItemActionPerformed

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_exitButtonActionPerformed

    private void buktiTransMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buktiTransMenuItemActionPerformed
        // TODO add your handling code here:
        BuktiTransaksiForm call = new BuktiTransaksiForm();
        call.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_buktiTransMenuItemActionPerformed

    private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
        try {
            // TODO add your handling code here:
            Login login = new Login();
            MenuUtamaController kontrol = MenuUtamaController.getKoneksiKontrol();
            login.setUser(userText.getText());
            Login.setLog(login);
            login = kontrol.cekUser(login.getUser());
//         int status.getKoneksi(log);
            if (userText.getText().isEmpty() && passText.getText().isEmpty()) {
                JOptionPane.showMessageDialog(null, "Error, Username dan Password belum diisi!");
            } else {
                if (login.getPass().equals("0")) {
                    JOptionPane.showMessageDialog(null, "Error, Username tidak terdaftar");
                } else {
                    if (passText.getText().equals(login.getPass())) {
                        if (login.getPass().contains("pp_")) {
                            this.show(true);
                            LoginDialog.show(false);
                            menuBarForm.setVisible(true);
                            menuMenu.getItem(1).setVisible(false);
                            menuMenu.getItem(0).setVisible(true);
                            menuMenu.getItem(3).setVisible(true);
                            userField.setText(login.getUser());
                            jabatanText.setText(login.getJabatan());
                            JOptionPane.showMessageDialog(null, "Berhasil Login sebagai Penjual Pulsa");
                        } else if (login.getPass().contains("ad_")) {
                            this.show(true);
                            LoginDialog.show(false);
                            menuBarForm.setVisible(true);
                            menuMenu.getItem(0).setVisible(false);
                            menuMenu.getItem(1).setVisible(true);
                            menuMenu.getItem(3).setVisible(false);
                            userField.setText(login.getUser());
                            jabatanText.setText(login.getJabatan());
                            JOptionPane.showMessageDialog(null, "Berhasil Login sebagai Owner");
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Error, password salah");
                    }
                }
            }
            login.setLog(login);


        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainMenuForm.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(
                    null, "Login GAGAL");

        } catch (IOException ex) {
            Logger.getLogger(MainMenuForm.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(
                    null, "Login GAGAL");

        } catch (SQLException ex) {
            Logger.getLogger(MainMenuForm.class.getName()).log(Level.SEVERE, null, ex);
//                JOptionPane.showMessageDialog(null, "Error, Username dan Password belum diisi!");
            JOptionPane.showMessageDialog(null, "Login GAGAL");
        }
    }//GEN-LAST:event_loginButtonActionPerformed

    private void logoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutMenuItemActionPerformed
        // TODO add your handling code here:

        int status = JOptionPane.showConfirmDialog(LoginDialog, "Apakah Anda Ingin Logout?");
        if (status == 0) {
//            menuBarForm.setVisible(false);
            jabatanText.setText(null);
            userField.setText(null);
            this.show(false);
            LoginDialog.setVisible(true);
            userText.setText(null);
            passText.setText(null);
        }


    }//GEN-LAST:event_logoutMenuItemActionPerformed

    private void passTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_passTextActionPerformed
        // TODO add your handling code here:
        loginButton.doClick();
    }//GEN-LAST:event_passTextActionPerformed

    private void userTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_userTextActionPerformed

    private void exitmenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitmenuItemActionPerformed
        // TODO add your handling code here:
        System.exit(0);
}//GEN-LAST:event_exitmenuItemActionPerformed

    private void helpMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuItemActionPerformed
        try {
            // TODO add your handling code here:
            Process p = Runtime.getRuntime().exec("cmd /c start SP3EF.chm");
        } catch (IOException ex) {
            Logger.getLogger(MainMenuForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_helpMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainMenuForm().setVisible(false);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog LoginDialog;
    private javax.swing.JLabel bgLabel;
    private javax.swing.JMenuItem buktiTransMenuItem;
    private javax.swing.JLabel copyrightLabel;
    private javax.swing.JButton exitButton;
    private javax.swing.JMenuItem exitmenuItem;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem helpMenuItem;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel jabatanText;
    private javax.swing.JLabel judulLabel;
    private javax.swing.JMenuItem laporanMenuItem;
    private javax.swing.JButton loginButton;
    private javax.swing.JLabel logo;
    private javax.swing.JMenuItem logoutMenuItem;
    private javax.swing.JMenuBar menuBarForm;
    private javax.swing.JMenu menuMenu;
    private javax.swing.JPanel panelUserDetail;
    private javax.swing.JPasswordField passText;
    private javax.swing.JMenuItem pembelianmenuItem;
    private javax.swing.JMenuItem penjualanmenuItem;
    private javax.swing.JLabel userField;
    private javax.swing.JTextField userText;
    // End of variables declaration//GEN-END:variables
}
